#include <stdio.h>
#include <string.h>
#define N 10
void input(int num[],char name[N][8]);
void sort(int num[],char name[N][8]);
void search(int n,int num[],char name[N][8]);
int main(){
    int num[N],number,flag=1,c;
    char name[N][8];
    input(num,name);
    sort(num,name);
    while(flag==1){
        printf("\ninput number to look for:\n");
        scanf("%d",&number);
        search(number,num,name);
        flag=0;
        return 0;
    }
}

void input(int num[],char name[N][8]){
    int i;
    for (i=0;i<N;i++){
        printf("input NO. and name:\n");
        scanf("%d",&num[i]);
        gets(name[i]);
    }
}

void sort(int num[],char name[N][8]){
    int i,j,min,templ;
    char temp2[8];
    for (i=0;i<N-1;i++){
        min=i;
        for(j=i;j<N;j++){
            if(num[min]>num[j]){
                min=j;
            }
        }
            templ=num[i];
            strcpy(temp2,name[i]);
            num[i]=num[min];
            strcpy(name[i],name[min]);
            num[min]=templ;
            strcpy(name[min],temp2);
            
        
    }
    printf("\nresult: \n");
    for(i=0;i<N;i++){
        printf("%d%10s\n",num[i],name[i]);
    }
}

void search(int n,int num[],char name[N][8]){
    int top,bott,mid,loca,sign;
    top=0;
    bott=N-1;
    loca=0;
    sign=1;
    if((n<num[0])||(n>num[N-1])){
        loca=-1;
    }
    while((sign==1)&&(top<=bott)){
        mid=(bott+top)/2;
        if(n==num[mid]){
            loca=mid;
            printf("NO. %d , his name is %s.",n,name[loca]);
            sign=-1;
        }else if(n<num[mid]){
            bott=mid-1;
        }else{
            top=mid+1;
        }
    }
}
